#include <bits/stdc++.h>
using namespace std;
int n;
void factorize(int x) {
  if (x == 1) {
    printf("1\n\n");
    return;
  }
  for (int i = 2; i <= x / i; ++i) {
    int cnt = 0;
    while (x % i == 0) {
      x /= i;
      cnt++;
    }
    if (cnt) printf("%d %d\n", i, cnt);
  }
  if (x > 1) printf("%d %d\n", x, 1);
  printf("\n");
}
int main() {
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    factorize(a);
  }
}

